package chances.wechat.log;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class WechatLoggerImpl implements WechatLogger {
	
	private String appId;
	
	public String getAppId() {
		return appId;
	}

	public void setAppId(String appId) {
		this.appId = appId;
	}

	private static final String FIX = "|";
	private static final Logger wxgw = LoggerFactory.getLogger("wxgwLogger");
	private static final Logger login = LoggerFactory.getLogger("userloginLogger");
	private static final Logger userInfo = LoggerFactory.getLogger("userInfoLogger");
	private static final Logger qrCode = LoggerFactory.getLogger("qrCodeLogger");
	private static final Logger qrScan = LoggerFactory.getLogger("qrScanLogger");
	private static final Logger message = LoggerFactory.getLogger("messageLogger");
	private static final Logger unbind = LoggerFactory.getLogger("unbindLogger");
	private static final Logger error = LoggerFactory.getLogger("errorLogger");

	@Override
	public void logToken(String appId, String accessToken, String resultJson) {
		StringBuffer sb = new StringBuffer();
		sb.append(appId).append(FIX)
		  .append(accessToken).append(FIX)
		  .append(resultJson);
		wxgw.info(sb.toString());
	}

	@Override
	public void logJsapiTicket(String accessToken, String jsApiTicket, String resultJson) {
		StringBuffer sb = new StringBuffer();
		sb.append(appId).append(FIX)
		  .append(accessToken).append(FIX)
		  .append(jsApiTicket).append(FIX)
		  .append(resultJson);
		wxgw.info(sb.toString());
	}

	@Override
	public void logLogin(String appId, String openId, String scope, String type, 
			String OAuthUrl, String target) {
		StringBuffer sb = new StringBuffer();
		sb.append(appId).append(FIX)
		  .append(openId).append(FIX)
		  .append(scope).append(FIX)
		  .append(type).append(FIX)
		  .append(target).append(FIX)
		  .append(OAuthUrl);
		login.info(sb.toString());
	}

	@Override
	public void logUserInfo(String accessToken, String openId, String resultJson, String reqUrl) {
		StringBuffer sb = new StringBuffer();
		sb.append(accessToken).append(FIX)
		  .append(openId).append(FIX)
		  .append(resultJson).append(FIX)
		  .append(reqUrl);
		userInfo.info(sb.toString());
	}

	@Override
	public void logQrCode(String iptvacct, String stbtype, String epgversion, String qrInfo, String target) {
		StringBuffer sb = new StringBuffer();
		sb.append(iptvacct).append(FIX)
		  .append(stbtype).append(FIX)
		  .append(epgversion).append(FIX)
		  .append(qrInfo).append(FIX)
		  .append(target);
		qrCode.info(sb.toString());
	}

	@Override
	public void logQrScan(String qrInfo, String openId, String stbNo, String resultJson, String qrcodeurl) {
		StringBuffer sb = new StringBuffer();
		sb.append(qrInfo).append(FIX)
		  .append(openId).append(FIX)
		  .append(stbNo).append(FIX)
		  .append(resultJson).append(FIX)
		  .append(qrcodeurl);
		qrScan.info(sb.toString());
	}

	@Override
	public void logMessage(String openId, String stbNo, String ctrlType, String contentType, 
			String contentCode, String body, String resultJson) {
		StringBuffer sb = new StringBuffer();
		sb.append(openId).append(FIX)
		  .append(stbNo).append(FIX)
		  .append(ctrlType).append(FIX)
		  .append(contentType).append(FIX)
		  .append(contentCode).append(FIX)
		  .append(body).append(FIX)
		  .append(resultJson);
		message.info(sb.toString());
	}

	@Override
	public void logStbUnbind(String openId, String stbNo, String bindId, String resultJson) {
		StringBuffer sb = new StringBuffer();
		sb.append(openId).append(FIX)
		  .append(stbNo).append(FIX)
		  .append(bindId).append(FIX)
		  .append(resultJson);
		unbind.info(sb.toString());
	}

	@Override
	public void logError(String errorMsg) {
		error.error(errorMsg);
	}

}
